package com.edu.exam.entity.curriculum.questionbank;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;

// External enum imports
import com.edu.exam.enums.curriculum.questionbank.Difficulty;
import com.edu.exam.enums.curriculum.questionbank.QuestionStatus;

/**
 * 多选题实体类
 * 所属模块：B-02 题库管理模块
 * 对应数据库表：mcq_questions
 *
 * 管理多选题的基础信息，包括题干内容、标题、难度级别、分类、状态等。
 * 支持多选题的创建、编辑、发布、归档等全生命周期管理。
 * 关联选项、评分规则、质量评估等关键信息，提供多选题的完整视图。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Comment("多选题基础信息表")
@SQLDelete(sql = "UPDATE mcq_questions SET is_deleted = true, delete_time = CURRENT_TIMESTAMP WHERE id = ?")
@Where(clause = "is_deleted = false")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class MultipleChoiceQuestion {

    /**
     * 多选题唯一标识符
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 题目标题，用于快速识别题目
     */
    @NotBlank(message = "题目标题不能为空")
    @Size(max = 500, message = "题目标题长度不能超过500个字符")
    @Column(name = "title", nullable = false, length = 500)
    private String title;

    /**
     * 题干内容，支持富文本格式
     */
    @NotBlank(message = "题干内容不能为空")
    @Column(name = "content", nullable = false, columnDefinition = "TEXT")
    private String content;

    /**
     * 题目解析说明，解释答案选择理由
     */
    @Column(name = "explanation", columnDefinition = "TEXT")
    private String explanation;

    /**
     * 难度级别
     */
    @NotNull(message = "难度级别不能为空")
    @Enumerated(EnumType.STRING)
    @Column(name = "difficulty", nullable = false, length = 20)
    private Difficulty difficulty;

    /**
     * 题目分类，如编程基础、数据结构等
     */
    @NotBlank(message = "题目分类不能为空")
    @Size(max = 100, message = "题目分类长度不能超过100个字符")
    @Column(name = "category", nullable = false, length = 100)
    private String category;

    /**
     * 标签列表，多个标签用逗号分隔
     */
    @Size(max = 500, message = "标签长度不能超过500个字符")
    @Column(name = "tags", length = 500)
    private String tags;

    /**
     * 题目状态
     */
    @NotNull(message = "题目状态不能为空")
    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false, length = 20)
    private QuestionStatus status;

    /**
     * 题目版本号，每次修改自动递增
     */
    @NotNull(message = "版本号不能为空")
    @Column(name = "version", nullable = false)
    @Builder.Default
    private Integer version = 1;

    /**
     * 创建者用户ID
     */
    @NotBlank(message = "创建者ID不能为空")
    @Size(max = 32, message = "创建者ID长度不能超过32个字符")
    @Column(name = "creator_id", nullable = false, length = 32)
    private String creatorId;

    /**
     * 创建者姓名，冗余存储便于查询
     */
    @NotBlank(message = "创建者姓名不能为空")
    @Size(max = 100, message = "创建者姓名长度不能超过100个字符")
    @Column(name = "creator_name", nullable = false, length = 100)
    private String creatorName;

    /**
     * 创建时间
     */
    @NotNull(message = "创建时间不能为空")
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 最后更新时间
     */
    @NotNull(message = "更新时间不能为空")
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 发布时间
     */
    @Column(name = "publish_time")
    private LocalDateTime publishTime;

    /**
     * 归档时间
     */
    @Column(name = "archive_time")
    private LocalDateTime archiveTime;

    /**
     * 预计答题时间，单位：秒
     */
    @Column(name = "estimated_time")
    private Integer estimatedTime;

    /**
     * 题目满分
     */
    @NotNull(message = "满分不能为空")
    @Column(name = "full_score", nullable = false, precision = 5, scale = 2)
    @Builder.Default
    private BigDecimal fullScore = BigDecimal.ZERO;

    /**
     * 知识点列表，多个知识点用逗号分隔
     */
    @Size(max = 500, message = "知识点长度不能超过500个字符")
    @Column(name = "knowledge_points", length = 500)
    private String knowledgePoints;

    /**
     * 题目来源，如教材名称、试卷名称等
     */
    @Size(max = 200, message = "题目来源长度不能超过200个字符")
    @Column(name = "source", length = 200)
    private String source;

    /**
     * 备注信息
     */
    @Column(name = "remarks", columnDefinition = "TEXT")
    private String remarks;

    /**
     * 软删除标记
     */
    @NotNull(message = "删除标记不能为空")
    @Column(name = "is_deleted", nullable = false)
    @Builder.Default
    private Boolean isDeleted = false;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    /**
     * 删除原因说明
     */
    @Size(max = 500, message = "删除原因长度不能超过500个字符")
    @Column(name = "delete_reason", length = 500)
    private String deleteReason;

  }